package com.java.thread.effective;

import java.util.ArrayList;
import java.util.List;

/**
 * User: wujun
 * Date: 2014/12/9
 */
public class ThreadWorker extends Worker {
    @Override
    public void run() {
        int num = reportNum();
        logger.debug("I am {} thread worker.", num);
        List<Thread> threads = new ArrayList<Thread>();
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(new RealWorker(num));
            thread.start();
            threads.add(thread);
        }
        for (Thread thread : threads) {
            try {
                thread.join(10);
            } catch (InterruptedException e) {
                logger.error("thread.join", e);
            }
        }
    }
}
